<?php
/* ******************************
	Incoming Tasks aJax actions
   ******************************
*/
	include('../../includes/classes/core.php');
	$action = $_REQUEST['act'];
	$start		=	$_REQUEST['start'];
    $end		=	$_REQUEST['end'];
	
	switch ($action) {
	    case 'get_list':
    	    $count = $_REQUEST['count'];
    	    
    	    $rResult = mysql_query("SELECT   	 production.id,
										         sale_transaction.end_date,
    	    									 production.code,
										         production.`name`,
										         production_unit.name,
										         SUM(sale_transaction_detail.product_quantity) AS `sum`,
										         sale_transaction_detail.self_cost AS `price`,
										         ROUND(SUM(sale_transaction_detail.product_quantity) * sale_transaction_detail.self_cost,2)
									FROM     	`sale_transaction`
									LEFT JOIN 	sale_transaction_detail ON sale_transaction.id = sale_transaction_detail.transaction_id
									LEFT JOIN 	production ON production.id = sale_transaction_detail.production_id
									LEFT JOIN 	production_unit ON production_unit.id = production.unit
									WHERE		DATE(sale_transaction.end_date) >= '$start' AND DATE(sale_transaction.end_date) <= '$end' AND sale_transaction.status != 10
									GROUP BY 	production.id,  sale_transaction.end_date");
			
			$output = array(
				"aaData"	=> array()
			);
			
			while ( $aRow = mysql_fetch_array( $rResult ) )
			{
				$row = array();
				for ( $i = 0 ; $i < $count ; $i++ )
				{
					/* General output */
					$row[] = $aRow[$i];
				}
				$output['aaData'][] = $row;
			}
			
			echo json_encode( $output );

	        break;	    
	    default:
	       	echo "null";
	}
?>